package com.ashok.interceptor;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ashok.action.LoginAction;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;


public class AuthenticationInterceptor extends AbstractInterceptor{
	private static final Logger LOGGER = LoggerFactory
			.getLogger(LoginAction.class);
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		Map<String, Object> session = invocation.getInvocationContext().getSession();
		LOGGER.info("User :"+session.get("user"));
		if(session.get("user")!=null){
			LOGGER.info("User :"+session.get("user") +" is a valid user");
			return invocation.invoke();
		}else{
			LOGGER.info("User :"+session.get("user") +" is not a valid user");
			return "Login";
		}
	}

	
}
